home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / TGE129C.ZIP / SOURCE / 360X480.ASM < prev    next >
Assembly Source File  |  1993-08-20  |  32KB  |  1,594 lines

  1. ; 360x480x256 (requires register-compatible VGA+)
  2. ; Loadable driver for The Graphics Engine
  3. ; Copyright (c) 1993 by Matthew Hildebrand
  4. ; Turbo Assembler syntax
  5.  
  6. IDEAL
  7. P486N            ; 386 code, but we want 486 alignment
  8. MODEL LARGE
  9.  
  10.  
  11. SCREEN_WIDE    =    360
  12. SCREEN_DEEP    =    480
  13. NUM_COLOURS    =    256
  14.  
  15.  
  16.         CODESEG
  17.         ORG    0
  18.  
  19. ;*** Signature
  20.             db    'TGE3'
  21. ;*** Non-I/O functions
  22. _initGraphics        dw    initGraphics        ; initGraphics
  23.             dw    ?
  24. _deInitGraphics        dw    0            ; deInitGraphics
  25.             dw    ?
  26. _setPaletteReg        dw    setPaletteReg        ; setPaletteReg
  27.             dw    ?
  28. _getPaletteReg        dw    getPaletteReg        ; getPaletteReg
  29.             dw    ?
  30. _setBlockPalette    dw    setBlockPalette        ; setBlockPalette
  31.             dw    ?
  32. _getBlockPalette    dw    getBlockPalette        ; getBlockPalette
  33.             dw    ?
  34. _colourCloseTo        dw    0            ; colourCloseTo
  35.             dw    ?
  36. _colourCloseToX        dw    0            ; colourCloseToX
  37.             dw    ?
  38. _imageSize        dw    0            ; imageSize
  39.             dw    ?
  40. _imageSizeDim        dw    0            ; imageSizeDim
  41.             dw    ?
  42. _setPage        dw    0            ; setPage (not implemented yet)
  43.             dw    ?
  44.  
  45. ;*** Currently active I/O functions (filled in by loadGraphDriver())
  46.             dd    20    DUP(?)
  47.  
  48. ;*** Input functions
  49. _getImage_scr        dw    0            ; getImage
  50.             dw    ?
  51. _getImage_mem        dw    0
  52.             dw    ?
  53. _getLine_scr        dw      getLine_scr              ; getLine
  54.             dw    ?
  55. _getLine_mem        dw    getLine_mem
  56.             dw    ?
  57. _getPixel_scr        dw    getPixel_scr        ; getPixel
  58.             dw    ?
  59. _getPixel_mem        dw    getPixel_mem
  60.             dw    ?
  61.  
  62. ;*** Output functions
  63. _putImage_scr_copy    dw    0            ; putImage
  64.             dw    ?
  65. _putImage_scr_and    dw    0
  66.             dw    ?
  67. _putImage_scr_not    dw    0
  68.             dw    ?
  69. _putImage_scr_or    dw    0
  70.             dw    ?
  71. _putImage_scr_xor    dw    0
  72.             dw    ?
  73. _putImage_mem_copy    dw    0
  74.             dw    ?
  75. _putImage_mem_and    dw    0
  76.             dw    ?
  77. _putImage_mem_not    dw    0
  78.             dw    ?
  79. _putImage_mem_or    dw    0
  80.             dw    ?
  81. _putImage_mem_xor    dw    0
  82.             dw    ?
  83. _putImageInv_scr_copy    dw    0            ; putImageInv
  84.             dw    ?
  85. _putImageInv_scr_and    dw    0
  86.             dw    ?
  87. _putImageInv_scr_not    dw      0
  88.             dw    ?
  89. _putImageInv_scr_or    dw      0
  90.             dw    ?
  91. _putImageInv_scr_xor    dw    0
  92.             dw    ?
  93. _putImageInv_mem_copy    dw    0
  94.             dw    ?
  95. _putImageInv_mem_and    dw    0
  96.             dw    ?
  97. _putImageInv_mem_not    dw    0
  98.             dw    ?
  99. _putImageInv_mem_or    dw    0
  100.             dw    ?
  101. _putImageInv_mem_xor    dw    0
  102.             dw    ?
  103. _putLine_scr_copy          dw    putLine_scr_copy    ; putLine
  104.             dw    ?
  105. _putLine_scr_and          dw      0
  106.             dw    ?
  107. _putLine_scr_not          dw      0
  108.             dw    ?
  109. _putLine_scr_or          dw      0
  110.             dw    ?
  111. _putLine_scr_xor          dw    0
  112.             dw    ?
  113. _putLine_mem_copy    dw      putLine_mem_copy
  114.             dw    ?
  115. _putLine_mem_and    dw      0
  116.             dw    ?
  117. _putLine_mem_not    dw      0
  118.             dw    ?
  119. _putLine_mem_or        dw      0
  120.             dw    ?
  121. _putLine_mem_xor    dw    0
  122.             dw    ?
  123. _putLineInv_scr_copy       dw    0            ; putLineInv
  124.             dw    ?
  125. _putLineInv_scr_and       dw    0
  126.             dw    ?
  127. _putLineInv_scr_not       dw    0
  128.             dw    ?
  129. _putLineInv_scr_or       dw    0
  130.             dw    ?
  131. _putLineInv_scr_xor       dw    0
  132.             dw    ?
  133. _putLineInv_mem_copy    dw    0
  134.             dw    ?
  135. _putLineInv_mem_and    dw    0
  136.             dw    ?
  137. _putLineInv_mem_not    dw    0
  138.             dw    ?
  139. _putLineInv_mem_or    dw    0
  140.             dw    ?
  141. _putLineInv_mem_xor    dw    0
  142.             dw    ?
  143. _putPixel_scr_copy    dw    putPixel_scr_copy    ; putPixel
  144.             dw    ?
  145. _putPixel_scr_and    dw      0
  146.             dw    ?
  147. _putPixel_scr_not    dw      0
  148.             dw    ?
  149. _putPixel_scr_or    dw      0
  150.             dw    ?
  151. _putPixel_scr_xor    dw    0
  152.             dw    ?
  153. _putPixel_mem_copy    dw    putPixel_mem_copy
  154.             dw    ?
  155. _putPixel_mem_and    dw      putPixel_mem_and
  156.             dw    ?
  157. _putPixel_mem_not    dw      putPixel_mem_not
  158.             dw    ?
  159. _putPixel_mem_or    dw      putPixel_mem_or
  160.             dw    ?
  161. _putPixel_mem_xor    dw    putPixel_mem_xor
  162.             dw    ?
  163. _line_scr_copy        dw    0            ; line
  164.             dw    ?
  165. _line_scr_and        dw      0
  166.             dw    ?
  167. _line_scr_not        dw      0
  168.             dw    ?
  169. _line_scr_or        dw      0
  170.             dw    ?
  171. _line_scr_xor        dw    0
  172.             dw    ?
  173. _line_mem_copy        dw    0
  174.             dw    ?
  175. _line_mem_and        dw    0
  176.             dw    ?
  177. _line_mem_not        dw    0
  178.             dw    ?
  179. _line_mem_or        dw    0
  180.             dw    ?
  181. _line_mem_xor        dw    0
  182.             dw    ?
  183. _horizLine_scr_copy    dw    horizLine_scr_copy      ; horizLine
  184.             dw    ?
  185. _horizLine_scr_and    dw      0
  186.             dw    ?
  187. _horizLine_scr_not    dw      0
  188.             dw    ?
  189. _horizLine_scr_or    dw      0
  190.             dw    ?
  191. _horizLine_scr_xor    dw    0
  192.             dw    ?
  193. _horizLine_mem_copy    dw    horizLine_mem_copy
  194.             dw    ?
  195. _horizLine_mem_and    dw      0
  196.             dw    ?
  197. _horizLine_mem_not    dw      0
  198.             dw    ?
  199. _horizLine_mem_or    dw      0
  200.             dw    ?
  201. _horizLine_mem_xor    dw    0
  202.             dw    ?
  203. _vertLine_scr_copy    dw    0             ; vertLine
  204.             dw    ?
  205. _vertLine_scr_and    dw    0
  206.             dw    ?
  207. _vertLine_scr_not    dw    0
  208.             dw    ?
  209. _vertLine_scr_or    dw    0
  210.             dw    ?
  211. _vertLine_scr_xor    dw    0
  212.             dw    ?
  213. _vertLine_mem_copy    dw    0
  214.             dw    ?
  215. _vertLine_mem_and    dw    0
  216.             dw    ?
  217. _vertLine_mem_not    dw    0
  218.             dw    ?
  219. _vertLine_mem_or    dw    0
  220.             dw    ?
  221. _vertLine_mem_xor    dw    0
  222.             dw    ?
  223. _drawRect_scr_copy    dw    0            ; drawRect
  224.             dw    ?
  225. _drawRect_scr_and    dw    0
  226.             dw    ?
  227. _drawRect_scr_not    dw    0
  228.             dw    ?
  229. _drawRect_scr_or    dw    0
  230.             dw    ?
  231. _drawRect_scr_xor    dw    0
  232.             dw    ?
  233. _drawRect_mem_copy    dw    0
  234.             dw    ?
  235. _drawRect_mem_and    dw    0
  236.             dw    ?
  237. _drawRect_mem_not    dw    0
  238.             dw    ?
  239. _drawRect_mem_or    dw    0
  240.             dw    ?
  241. _drawRect_mem_xor    dw    0
  242.             dw    ?
  243. _filledRect_scr_copy    dw    0            ; filledRect
  244.             dw    ?
  245. _filledRect_scr_and    dw      0
  246.             dw    ?
  247. _filledRect_scr_not    dw      0
  248.             dw    ?
  249. _filledRect_scr_or    dw      0
  250.             dw    ?
  251. _filledRect_scr_xor    dw    0
  252.             dw    ?
  253. _filledRect_mem_copy    dw    0
  254.             dw    ?
  255. _filledRect_mem_and    dw    0
  256.             dw    ?
  257. _filledRect_mem_not    dw    0
  258.             dw    ?
  259. _filledRect_mem_or    dw    0
  260.             dw    ?
  261. _filledRect_mem_xor    dw    0
  262.             dw    ?
  263. _clearGraphics_scr_copy    dw    clearGraphics_scr_copy    ; clearGraphics
  264.             dw    ?
  265. _clearGraphics_scr_and    dw      0
  266.             dw    ?
  267. _clearGraphics_scr_not    dw      0
  268.             dw    ?
  269. _clearGraphics_scr_or    dw      0
  270.             dw    ?
  271. _clearGraphics_scr_xor    dw    0
  272.             dw    ?
  273. _clearGraphics_mem_copy    dw    0
  274.             dw    ?
  275. _clearGraphics_mem_and    dw    0
  276.             dw    ?
  277. _clearGraphics_mem_not    dw    0
  278.             dw    ?
  279. _clearGraphics_mem_or    dw    0
  280.             dw    ?
  281. _clearGraphics_mem_xor    dw    0
  282.             dw    ?
  283. _ellipse_scr_copy    dw    0            ; ellipse
  284.             dw    ?
  285. _ellipse_scr_and    dw    0
  286.             dw    ?
  287. _ellipse_scr_not    dw    0
  288.             dw    ?
  289. _ellipse_scr_or        dw    0
  290.             dw    ?
  291. _ellipse_scr_xor    dw    0
  292.             dw    ?
  293. _ellipse_mem_copy    dw    0
  294.             dw    ?
  295. _ellipse_mem_and    dw    0
  296.             dw    ?
  297. _ellipse_mem_not    dw    0
  298.             dw    ?
  299. _ellipse_mem_or        dw    0
  300.             dw    ?
  301. _ellipse_mem_xor    dw    0
  302.             dw    ?
  303. _filledEllipse_scr_copy    dw    0            ; filledEllipse
  304.             dw    ?
  305. _filledEllipse_scr_and    dw    0
  306.             dw    ?
  307. _filledEllipse_scr_not    dw    0
  308.             dw    ?
  309. _filledEllipse_scr_or    dw    0
  310.             dw    ?
  311. _filledEllipse_scr_xor    dw    0
  312.             dw    ?
  313. _filledEllipse_mem_copy    dw    0
  314.             dw    ?
  315. _filledEllipse_mem_and    dw    0
  316.             dw    ?
  317. _filledEllipse_mem_not    dw    0
  318.             dw    ?
  319. _filledEllipse_mem_or    dw    0
  320.             dw    ?
  321. _filledEllipse_mem_xor    dw    0
  322.             dw    ?
  323. _circle_scr_copy    dw    0            ; circle
  324.             dw    ?
  325. _circle_scr_and        dw    0
  326.             dw    ?
  327. _circle_scr_not        dw    0
  328.             dw    ?
  329. _circle_scr_or        dw    0
  330.             dw    ?
  331. _circle_scr_xor        dw    0
  332.             dw    ?
  333. _circle_mem_copy    dw    0
  334.             dw    ?
  335. _circle_mem_and        dw    0
  336.             dw    ?
  337. _circle_mem_not        dw    0
  338.             dw    ?
  339. _circle_mem_or        dw    0
  340.             dw    ?
  341. _circle_mem_xor        dw    0
  342.             dw    ?
  343. _filledCircle_scr_copy    dw    0            ; filledCircle
  344.             dw    ?
  345. _filledCircle_scr_and    dw    0
  346.             dw    ?
  347. _filledCircle_scr_not    dw    0
  348.             dw    ?
  349. _filledCircle_scr_or    dw    0
  350.             dw    ?
  351. _filledCircle_scr_xor    dw    0
  352.             dw    ?
  353. _filledCircle_mem_copy    dw    0
  354.             dw    ?
  355. _filledCircle_mem_and    dw    0
  356.             dw    ?
  357. _filledCircle_mem_not    dw    0
  358.             dw    ?
  359. _filledCircle_mem_or    dw    0
  360.             dw    ?
  361. _filledCircle_mem_xor    dw    0
  362.             dw    ?
  363. _fillRegion_scr_copy    dw    0            ; fillRegion
  364.             dw    ?
  365. _fillRegion_scr_and    dw    0
  366.             dw    ?
  367. _fillRegion_scr_not    dw    0
  368.             dw    ?
  369. _fillRegion_scr_or    dw    0
  370.             dw    ?
  371. _fillRegion_scr_xor    dw    0
  372.             dw    ?
  373. _fillRegion_mem_copy    dw    0
  374.             dw    ?
  375. _fillRegion_mem_and    dw    0
  376.             dw    ?
  377. _fillRegion_mem_not    dw    0
  378.             dw    ?
  379. _fillRegion_mem_or    dw    0
  380.             dw    ?
  381. _fillRegion_mem_xor    dw    0
  382.             dw    ?
  383. _fillLine_scr_copy    dw    0            ; fillLine
  384.             dw    ?
  385. _fillLine_scr_and    dw      0
  386.             dw    ?
  387. _fillLine_scr_not    dw      0
  388.             dw    ?
  389. _fillLine_scr_or    dw      0
  390.             dw    ?
  391. _fillLine_scr_xor    dw    0
  392.             dw    ?
  393. _fillLine_mem_copy    dw    0
  394.             dw    ?
  395. _fillLine_mem_and    dw      0
  396.             dw    ?
  397. _fillLine_mem_not    dw      0
  398.             dw    ?
  399. _fillLine_mem_or    dw      0
  400.             dw    ?
  401. _fillLine_mem_xor    dw    0
  402.             dw    ?
  403. ;*** Mode information
  404. scrnMaxX        dw    359    ; physical dimensions
  405. scrnMaxY        dw    479
  406. maxColour        dw    255    ; maximum colour number
  407. xRatio                   dw    3    ; aspect ratio 3:4 (360:480 in
  408. yRatio            dw    4    ;   lowest terms)
  409. bitsPerPixel        dw    8    ; 8 bits per pixel
  410. inMaxX            dw    359    ; current input screen dimensions
  411. inMaxY            dw    479
  412. outMaxX            dw    359    ; current output screen dimensions
  413. outMaxY            dw    479
  414. inScreenWide        dw    ?    ; needed only for virtual screens
  415. outScreenWide        dw    ?
  416. ;*** Viewport information
  417. inViewportULX        dw    0
  418. inViewportULY        dw    0
  419. inViewportLRX        dw    359
  420. inViewportLRY        dw    479
  421. outViewportULX        dw    0
  422. outViewportULY        dw    0
  423. outViewportLRX        dw    359
  424. outViewportLRY        dw    479
  425. ;*** Paging information
  426. pagingSupported        dw    ?    ; not implemented yet
  427. curPage            dw    ?    ; not implemented yet
  428. maxPage            dw    ?    ; not implemented yet
  429. ;*** Force (image width MOD imageWideAdjust) = 0.
  430. imageWideAdjust        dw    ?    ; not implemented yet
  431. ;*** Current and screen addresses
  432.     LABEL    inAddr    DWORD        ; current input address
  433. inOff    dw    0
  434. inSeg    dw    0A000h
  435.     LABEL    outAddr    DWORD        ; current output address
  436. outOff    dw    0
  437. outSeg    dw    0A000h
  438.     LABEL    scrAddr    DWORD        ; screen address
  439. scrOff    dw    0
  440. scrSeg    dw    0A000h
  441. ;*** Copyright string
  442.     db    'The Graphics Engine -- Copyright (c) 1993 by Matthew Hildebrand'
  443.  
  444.  
  445. inited        db    0
  446. colourPalette    db    768    DUP(?)
  447. lineOffs    dw    480    DUP(?)
  448.  
  449. ; Plane masks for horizLine
  450. leftEdgeMask    db    1111b, 1110b, 1100b, 1000b
  451. rightEdgeMask    db    0001b, 0011b, 0111b, 1111b
  452.  
  453.  
  454. SC_INDEX    EQU    3C4h    ; Sequence Controller Index
  455. GC_INDEX    EQU    3CEh    ; Graphics Controller Index register
  456. CRTC_INDEX    EQU    3D4h    ; CRT Controller Index
  457. MISC_OUTPUT    EQU    3C2h    ; Miscellaneous Output register
  458. MAP_MASK    EQU     02h     ; index in SC of Map Mask register
  459. READ_MAP    EQU    4    ; Read Map register index in GC
  460. MEMORY_MODE    EQU    4    ; Memory mode register in SC
  461. GRAPHICS_MODE    EQU    5    ; Graphics Mode register index in GC
  462. MISCELLANEOUS    EQU    6    ; Miscellaneous register index in GC
  463. MAX_SCAN_LINE    EQU    9          ; Maximum Scan Line reg index in CRTC
  464. START_ADDR_HIGH    EQU    0Ch    ; Start Address High reg index in CRTC
  465. UNDERLINE    EQU    14h    ; Underline Location reg index in CRTC
  466. MODE_CONTROL    EQU    17h    ; Mode Control register index in CRTC
  467. INPUT_STATUS_1  EQU     03DAh   ; Input Status 1 register
  468. START_ADDR_HIGH EQU    0Ch     ; start address high byte
  469. START_ADDR_LOW  EQU    0Dh     ; start address low byte
  470. WORD_OUTS_OK    EQU    1    ; Set to 0 for VGAs that can't handle
  471.                 ; word OUTs to indexed VGA registers
  472.  
  473.  
  474. MACRO    OUT_WORD
  475. if WORD_OUTS_OK
  476.   out    dx,ax
  477. else
  478.   out    dx,al
  479.   inc    dx
  480.   xchg    ah,al
  481.   out    dx,al
  482.   dec    dx
  483.   xchg    ah,al
  484. endif
  485. ENDM
  486.  
  487.  
  488. ;*****
  489. ;***** initGraphics
  490. ;*****
  491.  
  492. PROC    C    initGraphics
  493.   push    si di
  494.  
  495.  
  496.   mov    ax,13h                ; start with standard mode 13h
  497.   int    10h                ; let the bios set the mode
  498.  
  499.   mov    dx,3C4h                ; alter sequencer registers
  500.   mov    ax,0604h            ; disable chain 4
  501.   out    dx,ax
  502.  
  503.   mov    ax,0F02h            ; set write plane mask to all bit planes
  504.   out    dx,ax
  505.   xor    di,di
  506.   mov    ax,0A000h
  507.   mov    es,ax
  508.   mov    cx,21600
  509.   xor    ax,ax
  510.   cld
  511.   rep    stosw                ; clear the whole of the screen
  512.  
  513.   mov    ax,0100h            ; synchronous reset
  514.   out    dx,ax                ; asserted
  515.   mov    dx,3C2h                ; misc output
  516.   mov    al,0E7h                ; use 28 mHz dot clock
  517.   out    dx,al                ; select it
  518.   mov    dx,3C4h                ; sequencer again
  519.   mov    ax,0300h            ; restart sequencer
  520.   out    dx,ax                ; running again
  521.  
  522.   mov    dx,3D4h                ; alter crtc registers
  523.  
  524.   mov    al,11h                ; cr11
  525.   out    dx,al                ; current value
  526.   inc    dx                ; point to data
  527.   in    al,dx                ; get cr11 value
  528.   and    al,7Fh                ; remove cr0 -> cr7
  529.   out    dx,al                ;    write protect
  530.   dec    dx                ; point to index
  531.  
  532.   mov    ax,06b00h            ; horz total
  533.   out    dx,ax
  534.   mov    ax,05901h            ; horz displayed
  535.   out    dx,ax
  536.   mov    ax,05a02h            ; start horz blanking
  537.   out    dx,ax
  538.   mov    ax,08e03h            ; end horz blanking
  539.   out    dx,ax
  540.   mov    ax,05e04h            ; start h sync
  541.   out    dx,ax
  542.   mov    ax,08a05h            ; end h sync
  543.   out    dx,ax
  544.   mov    ax,00d06h            ; vertical total
  545.   out    dx,ax
  546.   mov    ax,03e07h            ; overflow
  547.   out    dx,ax
  548.   mov    ax,04009h            ; cell height
  549.   out    dx,ax
  550.   mov    ax,0ea10h            ; v sync start
  551.   out    dx,ax
  552.   mov    ax,0ac11h            ; v sync end and protect cr0-cr7
  553.   out    dx,ax
  554.   mov    ax,0df12h            ; vertical displayed
  555.   out    dx,ax
  556.   mov    ax,02d13h            ; offset
  557.   out    dx,ax
  558.   mov    ax,00014h            ; turn off dword mode
  559.   out    dx,ax
  560.   mov    ax,0e715h            ; v blank start
  561.   out    dx,ax
  562.   mov    ax,00616h            ; v blank end
  563.   out    dx,ax
  564.   mov    ax,0e317h            ; turn on byte mode
  565.   out    dx,ax
  566.  
  567.  
  568.   cmp    [inited],0            ; restore palette if necessary
  569.   je    @@notInited
  570.   pop    di si
  571.   mov    ax,1
  572.   retf
  573.  
  574.     @@notInited:
  575.   mov    [inited],1
  576.   mov    si,OFFSET lineOffs
  577.   mov    cx,480
  578.   xor    bx,bx
  579.  
  580.     @@LLoop:
  581.   mov    ax,SCREEN_WIDE/4
  582.   mul    bx
  583.   mov    [cs:si],ax
  584.   add    si,2
  585.   inc    bx
  586.   loop    @@LLoop
  587.  
  588.   pop   di si
  589.   mov    ax,1
  590.   retf
  591. ENDP
  592.  
  593.  
  594. ;*****
  595. ;***** putLine
  596. ;*****
  597.  
  598. PROC    C    putLine_scr_copy
  599.     ARG    lineNum:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  600.         LOCAL    x2:WORD
  601.   push    ds si di
  602.  
  603.   mov    bx,[lineNum]            ; start address in ES:DI
  604.   shl    bx,1
  605.   mov    di,[lineOffs+bx]
  606.   mov    dx,[xOff]
  607.   shr    dx,2
  608.   add    di,dx
  609.   mov    ax,0A000h
  610.   mov    es,ax
  611.   lds    si,[buf]            ; source in DS:SI
  612.   cld
  613.  
  614.   mov    bx,[xOff]
  615.   add    bx,[lineLen]            ; calculate x2
  616.   dec    bx
  617.   mov    [x2],bx
  618.  
  619.   mov    cx,[lineLen]            ; line is short
  620.   cmp    cx,4
  621. JUMPS
  622.   jle    @@ShortLine
  623. NOJUMPS
  624.  
  625.   mov    cx,[xOff]            ; calculate starting plane
  626.   mov    bx,cx
  627.   mov    ax,0102h
  628.   and    cl,3
  629.   shl    ah,cl
  630.   mov    dx,SC_INDEX
  631.   OUT_WORD
  632.   push    si
  633.   mov    bx,[x2]
  634.   mov    cx,[xOff]
  635.       @@Loop1:
  636.   cmp    cx,bx
  637.   jg    @@Loop1Done
  638.   lodsb
  639.   stosb
  640.   add    cx,4
  641.   add    si,3
  642.   jmp    short    @@Loop1
  643.  
  644.     @@Loop1Done:
  645.   pop    si
  646.   inc    si
  647.   push    si
  648.   mov    bx,[xOff]
  649.   inc    bx
  650.   mov    cx,bx
  651.   mov    ax,0102h
  652.   and    cl,3
  653.   shl    ah,cl
  654.   mov    dx,SC_INDEX
  655.   OUT_WORD
  656.   mov    cx,bx
  657.   mov    bx,[lineNum]            ; start address in ES:DI
  658.   shl    bx,1
  659.   mov    di,[lineOffs+bx]
  660.   shr    cx,2
  661.   add    di,cx
  662.   mov    bx,[x2]
  663.   mov    cx,[xOff]
  664.   inc    cx
  665.       @@Loop2:
  666.   cmp    cx,bx
  667.   jg    @@Loop2Done
  668.   lodsb
  669.   stosb
  670.   add    cx,4
  671.   add    si,3
  672.   jmp    short    @@Loop2
  673.  
  674.       @@Loop2Done:
  675.   pop    si
  676.   inc    si
  677.   push    si
  678.   mov    bx,[xOff]
  679.   add    bx,2
  680.   mov    cx,bx
  681.   mov    ax,0102h
  682.   and    cl,3
  683.   shl    ah,cl
  684.   mov    dx,SC_INDEX
  685.   OUT_WORD
  686.   mov    cx,bx
  687.   mov    bx,[lineNum]
  688.   shl    bx,1
  689.   mov    di,[lineOffs+bx]
  690.   shr    cx,2
  691.   add    di,cx
  692.   mov    bx,[x2]
  693.   mov    cx,[xOff]
  694.   add    cx,2
  695.       @@Loop3:
  696.   cmp    cx,bx
  697.   jg    @@Loop3Done
  698.   lodsb
  699.   stosb
  700.   add    cx,4
  701.   add    si,3
  702.   jmp    short    @@Loop3
  703.  
  704.       @@Loop3Done:
  705.   pop    si
  706.   inc    si
  707.   mov    bx,[xOff]
  708.   add    bx,3
  709.   mov    cx,bx
  710.   mov    ax,0102h
  711.   and    cl,3
  712.   shl    ah,cl
  713.   mov    dx,SC_INDEX
  714.   OUT_WORD
  715.   mov    cx,bx
  716.   mov    bx,[lineNum]
  717.   shl    bx,1
  718.   mov    di,[lineOffs+bx]
  719.   shr    cx,2
  720.   add    di,cx
  721.   mov    bx,[x2]
  722.   mov    cx,[xOff]
  723.   add    cx,3
  724.     @@Loop4:
  725.   cmp    cx,bx
  726.   jg    @@Exit
  727.   lodsb
  728.   stosb
  729.   add    cx,4
  730.   add    si,3
  731.   jmp    short    @@Loop4
  732.  
  733.     @@ShortLine:
  734.   mov    cx,[xOff]
  735.   mov    bx,cx
  736.   and    cl,3
  737.   mov    ax,0102h
  738.   shl    ah,cl
  739.   mov    dx,SC_INDEX
  740.   OUT_WORD
  741.   mov    cx,bx
  742.   shr    bx,2
  743.   mov    di,bx
  744.   mov    bx,[lineNum]
  745.   shl    bx,1
  746.   add    di,[lineOffs+bx]
  747.   movsb
  748.   cmp    cx,[x2]
  749.   jge    @@Exit
  750.   inc    [xOff]
  751.   jmp    short    @@ShortLine
  752.  
  753.     @@Exit:
  754.   pop   di si ds
  755.   leave
  756.   retf
  757. ENDP
  758.  
  759. PROC    C    putLine_mem_copy
  760.     ARG    y:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  761.   push    ds si di            ; save these registers
  762.  
  763.   xor    eax,eax                ; clear EAX
  764.   xor    edx,edx                ; clear EDX
  765.   xor    edi,edi                ; clear EDI
  766.  
  767.   les    di,[outAddr]            ; load output address
  768.   mov    ax,[y]
  769.   mov    dx,[outScreenWide]
  770.   mul    edx                    ; EDX:EAX = offset - EDI - x
  771.   add    edi,eax                ; EDI = offset - x
  772.   mov    dx,[xOff]
  773.   add    edi,edx                ; EDI = offset
  774.   mov    edx,edi                ; EDX = offset
  775.   shr    edx,4                ; EDX = # of paragraphs (segments)
  776.   add    dx,[outSeg]            ; DX = new segment
  777.   mov    es,dx                ; ES = new segment
  778.   and    di,0000000000001111b             ; DI = offset within new segment
  779.  
  780.   lds    si,[buf]            ; load input address
  781.   mov    dx,si                ; DX = offset
  782.   shr    dx,4                ; DX = # of paragraphs (segments)
  783.   mov    ax,ds                ; AX = DS
  784.   add    ax,dx                ; AX = new DS
  785.   mov    ds,ax                ; DS = new DS
  786.   and    si,0000000000001111b        ; SI = offset within new segment
  787.  
  788.   cld
  789.   mov    cx,[lineLen]            ; CX = line length
  790.   mov    dx,cx                ; DX = line length
  791.   shr    cx,2                ; CX = line length in dwords
  792.   rep    movsd                     ; move the dwords if necessary
  793.   mov    cx,dx                ; CX = line length in bytes
  794.   and    cx,0000000000000011b        ; CX = any residual bytes
  795.   rep    movsb                ; move the bytes if necessary
  796.  
  797.   pop    di si ds            ; restore registers
  798.   leave                    ; clean up
  799.   retf                    ; return
  800. ENDP
  801.  
  802.  
  803. ;*****
  804. ;***** getLine
  805. ;*****
  806.  
  807. PROC    C    getLine_scr
  808.     ARG    lineNum:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  809.     LOCAL    x2:WORD
  810.   push    ds si di
  811.  
  812.   mov    bx,[lineNum]            ; start address in ES:DI
  813.   shl    bx,1
  814.   mov    si,[lineOffs+bx]
  815.   mov    dx,[xOff]
  816.   shr    dx,2
  817.   add    si,dx
  818.   mov    ax,0A000h
  819.   mov    ds,ax
  820.   les    di,[buf]            ; buffer addr in DS:SI
  821.   cld
  822.  
  823.   mov    bx,[xOff]
  824.   add    bx,[lineLen]            ; calculate x2
  825.   dec    bx
  826.   mov    [x2],bx
  827.  
  828.   mov    cx,[lineLen]            ; line is short
  829.   cmp    cx,4
  830. JUMPS
  831.   jle    @@ShortLine
  832. NOJUMPS
  833.  
  834.   mov    ax,[xOff]            ; calculate starting plane
  835.   mov    bx,ax
  836.   and    al,3
  837.   mov    ah,al
  838.   mov    al,READ_MAP
  839.   mov    dx,GC_INDEX
  840.   OUT_WORD
  841.   push    di
  842.   mov    bx,[x2]
  843.   mov    cx,[xOff]
  844.     @@Loop1:
  845.   cmp    cx,bx
  846.   jg    @@Loop1Done
  847.   lodsb
  848.   stosb
  849.   add    cx,4
  850.   add    di,3
  851.   jmp    short    @@Loop1
  852.  
  853.     @@Loop1Done:
  854.   pop    di
  855.   inc    di
  856.   push    di
  857.   mov    bx,[xOff]
  858.   inc    bx
  859.   mov    ax,bx
  860.   and    al,3
  861.   mov    ah,al
  862.   mov    al,READ_MAP
  863.   mov    dx,GC_INDEX
  864.   OUT_WORD
  865.   mov    cx,bx
  866.   mov    bx,[lineNum]            ; start address in ES:DI
  867.   shl    bx,1
  868.   mov    si,[lineOffs+bx]
  869.   shr    cx,2
  870.   add    si,cx
  871.   mov    bx,[x2]
  872.   mov    cx,[xOff]
  873.   inc    cx
  874.     @@Loop2:
  875.   cmp    cx,bx
  876.   jg    @@Loop2Done
  877.   lodsb
  878.   stosb
  879.   add    cx,4
  880.   add    di,3
  881.   jmp    short    @@Loop2
  882.  
  883.     @@Loop2Done:
  884.   pop    di
  885.   inc    di
  886.   push    di
  887.   mov    bx,[xOff]
  888.   add    bx,2
  889.   mov    ax,bx
  890.   and    al,3
  891.   mov    ah,al
  892.   mov    al,READ_MAP
  893.   mov    dx,GC_INDEX
  894.   OUT_WORD
  895.   mov    cx,bx
  896.   mov    bx,[lineNum]
  897.   shl    bx,1
  898.   mov    si,[lineOffs+bx]
  899.   shr    cx,2
  900.   add    si,cx
  901.   mov    bx,[x2]
  902.   mov    cx,[xOff]
  903.   add    cx,2
  904.     @@Loop3:
  905.   cmp    cx,bx
  906.   jg    @@Loop3Done
  907.   lodsb
  908.   stosb
  909.   add    cx,4
  910.   add    di,3
  911.   jmp    short    @@Loop3
  912.  
  913.     @@Loop3Done:
  914.   pop    di
  915.   inc    di
  916.   mov    bx,[xOff]
  917.   add    bx,3
  918.   mov    ax,bx
  919.   and    al,3
  920.   mov    ah,al
  921.   mov    al,READ_MAP
  922.   mov    dx,GC_INDEX
  923.   OUT_WORD
  924.   mov    cx,bx
  925.   mov    bx,[lineNum]
  926.   shl    bx,1
  927.   mov    si,[lineOffs+bx]
  928.   shr    cx,2
  929.   add    si,cx
  930.   mov    bx,[x2]
  931.   mov    cx,[xOff]
  932.   add    cx,3
  933.     @@Loop4:
  934.   cmp    cx,bx
  935.   jg    @@Exit
  936.   lodsb
  937.   stosb
  938.   add    cx,4
  939.   add    di,3
  940.   jmp    short    @@Loop4
  941.  
  942.     @@ShortLine:
  943.   mov    ax,[xOff]
  944.   mov    bx,ax
  945.   and    al,3
  946.   mov    ah,al
  947.   mov    al,READ_MAP
  948.   mov    dx,GC_INDEX
  949.   OUT_WORD
  950.   mov    cx,bx
  951.   shr    bx,2
  952.   mov    si,bx
  953.   mov    bx,[lineNum]
  954.   shl    bx,1
  955.   add    si,[lineOffs+bx]
  956.   movsb
  957.   cmp    cx,[x2]
  958.   jge    @@Exit
  959.   inc    [xOff]
  960.   jmp    short    @@ShortLine
  961.  
  962.     @@Exit:
  963.   pop   di si ds
  964.   leave
  965.   retf
  966. ENDP
  967.  
  968. PROC    C    getLine_mem
  969.     ARG    y:WORD, xOff:WORD, lineLen:WORD, buf:DATAPTR
  970.   push    ds si di            ; save these registers
  971.  
  972.   xor    eax,eax                ; clear EAX
  973.   xor    edx,edx                ; clear EDX
  974.   xor    esi,esi                ; clear ESI
  975.  
  976.   les    si,[inAddr]            ; load input address
  977.   mov    ax,[y]
  978.   mov    dx,[inScreenWide]
  979.   mul    edx                    ; EDX:EAX = offset - ESI - x
  980.   add    esi,eax                ; ESI = offset - x
  981.   mov    dx,[xOff]
  982.   add    esi,edx                ; ESI = offset
  983.   mov    edx,esi                ; EDX = offset
  984.   shr    edx,4                ; EDX = # of paragraphs (segments)
  985.   add    dx,[inSeg]            ; DX = new segment
  986.   mov    ds,dx                ; ES = new segment
  987.   and    si,0000000000001111b             ; SI = offset within new segment
  988.  
  989.   les    di,[buf]            ; load output address
  990.   mov    dx,di                ; DX = offset
  991.   shr    dx,4                ; DX = # of paragraphs (segments)
  992.   mov    ax,es                ; AX = ES
  993.   add    ax,dx                ; AX = new ES
  994.   mov    es,ax                ; ES = new ES
  995.   and    di,0000000000001111b        ; DI = offset within new segment
  996.  
  997.   cld
  998.   mov    cx,[lineLen]            ; CX = line length
  999.   mov    dx,cx                ; DX = line length
  1000.   shr    cx,2                ; CX = line length in dwords
  1001.   rep    movsd                     ; move the dwords if necessary
  1002.   mov    cx,dx                ; CX = line length in bytes
  1003.   and    cx,0000000000000011b        ; CX = any residual bytes
  1004.   rep    movsb                ; move the bytes if necessary
  1005.  
  1006.   pop    di si ds            ; restore registers
  1007.   leave                    ; clean up
  1008.   retf                    ; return
  1009. ENDP
  1010.  
  1011.  
  1012. ;*****
  1013. ;***** putPixel
  1014. ;*****
  1015.  
  1016. ; Copy a pixel to the screen
  1017. PROC    C    putPixel_scr_copy
  1018.     ARG    x:WORD, y:WORD, colour:BYTE
  1019.   push    di
  1020.  
  1021.   mov    ax,0A000h
  1022.   mov    es,ax
  1023.   mov    bx,[y]                ; point to start of desired row
  1024.   shl    bx,1
  1025.   mov    bx,[lineOffs+bx]
  1026.   mov    dx,[x]
  1027.   mov    cx,dx                ; store x coord
  1028.   shr    dx,2
  1029.   add    bx,dx
  1030.   mov    di,bx                ; ES:DI points to pixel
  1031.   and    cl,3                ; get the plane # of the pixel
  1032.   mov    ax,102h
  1033.   shl    ah,cl                ; set the bit corresponding to plane
  1034.   mov    dx,SC_INDEX
  1035.   OUT_WORD
  1036.   mov    bl,[colour]
  1037.   mov    [es:di],bl
  1038.  
  1039.   pop    di
  1040.   leave
  1041.   retf
  1042. ENDP
  1043.  
  1044. ; Copy a pixel to memory
  1045. PROC    C    putPixel_mem_copy
  1046.     ARG    x:WORD,y:WORD,colour:BYTE
  1047.   xor    eax,eax                ; clear EAX
  1048.   xor    ebx,ebx                ; clear EBX
  1049.   xor    edx,edx                ; clear EDX
  1050.  
  1051.   les    bx,[outAddr]            ; load output address
  1052.   mov    ax,[y]
  1053.   mov    dx,[outScreenWide]
  1054.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1055.   add    ebx,eax                ; EBX = offset - x
  1056.   mov    dx,[x]
  1057.   add    ebx,edx                ; EBX = offset
  1058.  
  1059.   mov    edx,ebx                ; EDX = offset
  1060.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1061.   add    dx,[outSeg]            ; DX = new segment
  1062.   mov    es,dx                ; ES = new segment
  1063.   and    bx,0000000000001111b             ; BX = offset within new segment
  1064.  
  1065.   mov    al,[colour]            ; colour in AL
  1066.   mov    [es:bx],al            ; store pixel
  1067.   leave                    ; clean up
  1068.   retf                    ; return
  1069. ENDP
  1070.  
  1071. ; AND a pixel to memory
  1072. PROC    C    putPixel_mem_and
  1073.     ARG    x:WORD,y:WORD,colour:BYTE
  1074.   xor    eax,eax                ; clear EAX
  1075.   xor    ebx,ebx                ; clear EBX
  1076.   xor    edx,edx                ; clear EDX
  1077.  
  1078.   les    bx,[outAddr]            ; load output address
  1079.   mov    ax,[y]
  1080.   mov    dx,[outScreenWide]
  1081.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1082.   add    ebx,eax                ; EBX = offset - x
  1083.   mov    dx,[x]
  1084.   add    ebx,edx                ; EBX = offset
  1085.  
  1086.   mov    edx,ebx                ; EDX = offset
  1087.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1088.   add    dx,[outSeg]            ; DX = new segment
  1089.   mov    es,dx                ; ES = new segment
  1090.   and    bx,0000000000001111b             ; BX = offset within new segment
  1091.  
  1092.   mov    al,[colour]            ; colour in AL
  1093.   and    [es:bx],al            ; AND pixel
  1094.   leave                    ; clean up
  1095.   retf                    ; return
  1096. ENDP
  1097.  
  1098. ; NOT a pixel to memory
  1099. PROC    C    putPixel_mem_not
  1100.     ARG    x:WORD,y:WORD,colour:BYTE
  1101.   xor    eax,eax                ; clear EAX
  1102.   xor    ebx,ebx                ; clear EBX
  1103.   xor    edx,edx                ; clear EDX
  1104.  
  1105.   les    bx,[outAddr]            ; load output address
  1106.   mov    ax,[y]
  1107.   mov    dx,[outScreenWide]
  1108.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1109.   add    ebx,eax                ; EBX = offset - x
  1110.   mov    dx,[x]
  1111.   add    ebx,edx                ; EBX = offset
  1112.  
  1113.   mov    edx,ebx                ; EDX = offset
  1114.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1115.   add    dx,[outSeg]            ; DX = new segment
  1116.   mov    es,dx                ; ES = new segment
  1117.   and    bx,0000000000001111b             ; BX = offset within new segment
  1118.  
  1119.   mov    al,[colour]            ; colour in AL
  1120.   not    al                ; NOT it
  1121.   mov    [es:bx],al            ; store NOTed pixel
  1122.   leave                    ; clean up
  1123.   retf                    ; return
  1124. ENDP
  1125.  
  1126. ; OR a pixel to memory
  1127. PROC    C    putPixel_mem_or
  1128.     ARG    x:WORD,y:WORD,colour:BYTE
  1129.   xor    eax,eax                ; clear EAX
  1130.   xor    ebx,ebx                ; clear EBX
  1131.   xor    edx,edx                ; clear EDX
  1132.  
  1133.   les    bx,[outAddr]            ; load output address
  1134.   mov    ax,[y]
  1135.   mov    dx,[outScreenWide]
  1136.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1137.   add    ebx,eax                ; EBX = offset - x
  1138.   mov    dx,[x]
  1139.   add    ebx,edx                ; EBX = offset
  1140.  
  1141.   mov    edx,ebx                ; EDX = offset
  1142.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1143.   add    dx,[outSeg]            ; DX = new segment
  1144.   mov    es,dx                ; ES = new segment
  1145.   and    bx,0000000000001111b             ; BX = offset within new segment
  1146.  
  1147.   mov    al,[colour]            ; colour in AL
  1148.   or    [es:bx],al            ; OR pixel
  1149.   leave                    ; clean up
  1150.   retf                    ; return
  1151. ENDP
  1152.  
  1153. ; XOR a pixel to memory
  1154. PROC    C    putPixel_mem_xor
  1155.     ARG    x:WORD,y:WORD,colour:BYTE
  1156.   xor    eax,eax                ; clear EAX
  1157.   xor    ebx,ebx                ; clear EBX
  1158.   xor    edx,edx                ; clear EDX
  1159.  
  1160.   les    bx,[outAddr]            ; load output address
  1161.   mov    ax,[y]
  1162.   mov    dx,[outScreenWide]
  1163.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1164.   add    ebx,eax                ; EBX = offset - x
  1165.   mov    dx,[x]
  1166.   add    ebx,edx                ; EBX = offset
  1167.  
  1168.   mov    edx,ebx                ; EDX = offset
  1169.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1170.   add    dx,[outSeg]            ; DX = new segment
  1171.   mov    es,dx                ; ES = new segment
  1172.   and    bx,0000000000001111b             ; BX = offset within new segment
  1173.  
  1174.   mov    al,[colour]            ; colour in AL
  1175.   xor    [es:bx],al            ; XOR pixel
  1176.   leave                    ; clean up
  1177.   retf                    ; return
  1178. ENDP
  1179.  
  1180.  
  1181. ;*****
  1182. ;***** getPixel
  1183. ;*****
  1184.  
  1185. PROC    C    getPixel_scr
  1186.     ARG    x:WORD, y:WORD
  1187.   push    di
  1188.  
  1189.   mov    ax,0A000h
  1190.   mov    es,ax
  1191.   mov    bx,[y]                ; point to start of desired row
  1192.   shl    bx,1
  1193.   mov    bx,[lineOffs+bx]
  1194.   mov    dx,[x]
  1195.   mov    cx,dx                ; store x coord
  1196.   shr    dx,2
  1197.   add    bx,dx
  1198.   mov    di,bx                ; ES:DI points to pixel
  1199.   and    cl,3                ; get the plane # of the pixel
  1200.   mov    al,READ_MAP
  1201.   mov    ah,cl
  1202.   mov    dx,GC_INDEX            ; set the bit corresponding to plane
  1203.   OUT_WORD
  1204.   xor    ax,ax
  1205.   mov    al,[es:di]
  1206.  
  1207.   pop    di
  1208.   leave
  1209.   retf
  1210. ENDP
  1211.  
  1212. ; Get a pixel from memory
  1213. PROC    C    getPixel_mem
  1214.     ARG    x:WORD,y:WORD
  1215.   xor    eax,eax                ; clear EAX
  1216.   xor    ebx,ebx                ; clear EBX
  1217.   xor    edx,edx                ; clear EDX
  1218.  
  1219.   les    bx,[inAddr]            ; load input address
  1220.   mov    ax,[y]
  1221.   mov    dx,[inScreenWide]
  1222.   mul    edx                    ; EDX:EAX = offset - EBX - x
  1223.   add    ebx,eax                ; EBX = offset - x
  1224.   mov    dx,[x]
  1225.   add    ebx,edx                ; EBX = offset
  1226.  
  1227.   mov    edx,ebx                ; EDX = offset
  1228.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1229.   add    dx,[inSeg]            ; DX = new segment
  1230.   mov    es,dx                ; ES = new segment
  1231.   and    bx,0000000000001111b             ; BX = offset within new segment
  1232.  
  1233.   xor    ax,ax                ; clear AX
  1234.   mov    al,[es:bx]            ; store pixel in AX for return
  1235.   leave                    ; clean up
  1236.   retf                    ; return
  1237. ENDP
  1238.  
  1239.  
  1240. ;*****
  1241. ;***** horizLine
  1242. ;*****
  1243.  
  1244. PROC    C    horizLine_scr_copy
  1245.     ARG    y:WORD, x1:WORD, x2:WORD, colour:BYTE
  1246.     LOCAL    adj1:WORD, adj2:WORD
  1247.   push    si di
  1248.   cld
  1249.  
  1250.   mov    ax,[x1]                ; set up adj1
  1251.   and    ax,3
  1252.   jz    @@adj1A
  1253.   mov    bx,4
  1254.   sub    bx,ax
  1255.   mov    ax,[x1]
  1256.   add    ax,bx
  1257.   mov    [adj1],ax
  1258.   jmp    short    @@adj1B
  1259.     @@adj1A:
  1260.   mov    ax,[x1]
  1261.   mov    [adj1],ax
  1262.     @@adj1B:
  1263.  
  1264.   mov    ax,[x2]                ; set up adj2
  1265.   mov    [adj2],ax
  1266.   and    ax,3
  1267.   sub    [adj2],ax
  1268.  
  1269.   mov    ax,[x1]                ; ensure x1 <= x2
  1270.   cmp    ax,[x2]
  1271.   jbe    @@setup
  1272.   mov    bx,[x2]
  1273.   mov    [x1],bx
  1274.   mov    [x2],ax
  1275.  
  1276.     @@setup:
  1277.   mov    ax,0A000h            ; set ES:DI to line start address
  1278.   mov    es,ax
  1279.   mov    bx,[y]
  1280.   shl    bx,1
  1281.   mov    di,[lineOffs+bx]
  1282.   mov    bx,[x1]                ; current x counter
  1283.   shr    bx,2
  1284.   add    di,bx
  1285.  
  1286.   mov    cx,[adj2]            ; CX = # of 4-pixel sets starting
  1287.   shr    cx,2                            ; on plane 0
  1288.   mov    bx,[adj1]
  1289.   shr    bx,2
  1290.   sub    cx,bx
  1291.  
  1292.   cmp    cx,1
  1293.   jl    @@shortLine
  1294.  
  1295.   ; Draw the left edge
  1296.   mov    ax,[x1]                ; get plane number of pixel #1
  1297.   and    ax,3
  1298.   jz    @@planeZeroStart        ; starts at plane zero
  1299.   mov    si,ax                ; set for pixels
  1300.   mov    ah,[leftEdgeMask+si]
  1301.   mov    al,MAP_MASK
  1302.   mov    dx,SC_INDEX
  1303.   OUT_WORD
  1304.   mov    al,[colour]
  1305.   stosb
  1306.  
  1307.   ; Draw the interior stretch
  1308.     @@planeZeroStart:
  1309.   mov    ax,0F02h            ; enable writes to all planes
  1310.   mov    dx,SC_INDEX
  1311.   OUT_WORD
  1312.   mov    al,[colour]
  1313.   mov    ah,al
  1314.   shr    cx,1
  1315.   jc    @@Odd
  1316.   rep    stosw                ; even number of pixels
  1317.   jmp    short    @@rightEdge
  1318.     @@Odd:
  1319.   rep    stosw                ; odd number of pixels
  1320.   stosb
  1321.  
  1322.   ; Draw the right edge
  1323.     @@rightEdge:
  1324.   mov    ax,[x2]                ; get plane number of last pixel
  1325.   and    ax,3
  1326.   mov    si,ax                ; set for pixels
  1327.   mov    ah,[rightEdgeMask+si]
  1328.   mov    al,MAP_MASK
  1329.   mov    dx,SC_INDEX
  1330.   OUT_WORD
  1331.   mov    al,[colour]
  1332.   stosb
  1333.  
  1334.     @@Exit:
  1335.   pop    di si                ; clean up and go home
  1336.   leave
  1337.   retf
  1338.  
  1339.     @@shortLine:            ; for very small lines
  1340.   mov    al,[colour]
  1341.   mov    cx,[x1]
  1342.   mov    dx,[y]
  1343.     @@Loop:
  1344.   push    ax cx dx            ; slow loop until done
  1345.   call    putPixel_scr_copy C, cx, dx, ax
  1346.   pop    dx cx ax
  1347.   inc    cx
  1348.   cmp    cx,[x2]
  1349.   jle    @@Loop
  1350.  
  1351.   pop     di si
  1352.   leave
  1353.   retf
  1354. ENDP
  1355.  
  1356. PROC    C    horizLine_mem_copy
  1357.     ARG    y:WORD, x1:WORD, x2:WORD, colour:BYTE
  1358.   push    edi                ; store EDI
  1359.  
  1360.   xor    eax,eax                ; clear EAX
  1361.   xor    edi,edi                ; clear EDI
  1362.   xor    edx,edx                ; clear EDX
  1363.  
  1364.   les    di,[outAddr]            ; load output address
  1365.   mov    ax,[y]
  1366.   mov    dx,[outScreenWide]
  1367.   mul    edx                    ; EDX:EAX = offset - EDI - x
  1368.   add    edi,eax                ; EDI = offset - x
  1369.   mov    dx,[x1]
  1370.   add    edi,edx                ; EDI = offset
  1371.   mov    edx,edi                ; EDX = offset
  1372.   shr    edx,4                ; EDX = # of paragraphs (segments)
  1373.   add    dx,[outSeg]            ; DX = new segment
  1374.   mov    es,dx                ; ES = new segment
  1375.   and    di,0000000000001111b             ; DI = offset within new segment
  1376.  
  1377.   mov    al,[colour]            ; colour in AL
  1378.   mov    ah,al                ; colour in AH
  1379.   mov    bx,ax
  1380.   shl    eax,16
  1381.   mov    ax,bx                 ; colour in each byte of EAX
  1382.  
  1383.   mov    cx,[x2]
  1384.   sub    cx,[x1]
  1385.   inc    cx                ; CX = line length in pixels
  1386.   mov    dx,cx                ; DX = line length in bytes
  1387.  
  1388.   shr    cx,2                ; CX = line length in dwords
  1389.   rep    stosd                ; store four bytes at a time
  1390.   mov    cx,dx                ; CX = line length in pixels
  1391.   and    cx,0000000000000011b        ; CX = any remaining bytes
  1392.   rep    stosb                ; store the remaining bytes
  1393.  
  1394.   pop    edi                    ; restore EDI
  1395.   leave                    ; clean up
  1396.   retf                    ; return
  1397. ENDP
  1398.  
  1399.  
  1400. ;*****
  1401. ;***** setPaletteReg
  1402. ;*****
  1403.  
  1404. PROC    C    setPaletteReg
  1405.     ARG    palNum:WORD,red:BYTE,green:BYTE,blue:BYTE
  1406.   mov    bx,[palNum]
  1407.  
  1408.   mov    dx,3C8h                ; set for the right palette register
  1409.   mov    ax,[palNum]
  1410.   out    dx,al
  1411.   inc    dx
  1412.  
  1413.   mov    al,[red]            ; red
  1414.   shr    al,2
  1415.   jnc    @@L1
  1416.   cmp    al,63
  1417.   je    @@L1
  1418.   inc    al
  1419.     @@L1:
  1420.   out    dx,al
  1421.  
  1422.   mov    al,[green]            ; green
  1423.   shr    al,2
  1424.   jnc    @@L2
  1425.   cmp    al,63
  1426.   je    @@L2
  1427.   inc    al
  1428.     @@L2:
  1429.   out    dx,al
  1430.  
  1431.   mov    al,[blue]            ; blue
  1432.   shr    al,2
  1433.   jnc    @@L3
  1434.   cmp    al,63
  1435.   je    @@L3
  1436.   inc    al
  1437.     @@L3:
  1438.   out    dx,al
  1439.  
  1440.   leave
  1441.   retf
  1442. ENDP
  1443.  
  1444.  
  1445. ;*****
  1446. ;***** getPaletteReg
  1447. ;*****
  1448.  
  1449. PROC    C    getPaletteReg
  1450.     ARG    palNum:WORD,red:DATAPTR,green:DATAPTR,blue:DATAPTR
  1451.   push    ds si
  1452.  
  1453.   mov    dx,3C7h                ; set for right palette register
  1454.   mov    ax,[palNum]
  1455.   out    dx,al
  1456.   mov    dx,3C9h
  1457.  
  1458.   in    al,dx                ; red
  1459.   lds    si,[red]
  1460.   shl    al,2
  1461.   mov    [ds:si],al
  1462.   in    al,dx                ; green
  1463.   lds    si,[green]
  1464.   shl    al,2
  1465.   mov    [ds:si],al
  1466.   in    al,dx                ; blue
  1467.   lds    si,[blue]
  1468.   shl    al,2
  1469.   mov    [ds:si],al
  1470.  
  1471.   pop    si ds
  1472.   leave
  1473.   retf
  1474. ENDP
  1475.  
  1476.  
  1477. ;*****
  1478. ;***** setBlockPalette
  1479. ;*****
  1480.  
  1481. PROC    C    setBlockPalette
  1482.     ARG    firstReg:WORD,lastReg:WORD,paletteData:DATAPTR
  1483.   push    ds si
  1484.  
  1485.   lds    si,[paletteData]        ; set up
  1486.   mov    dx,3C8h
  1487.   mov    ax,[firstReg]
  1488.   out    dx,al
  1489.   inc    dx
  1490.   mov    cx,[lastReg]            ; CX = number of registers
  1491.   sub    cx,ax
  1492.   inc    cx
  1493.   cld
  1494.  
  1495.     @@LLoop:
  1496.   lodsb            ; red
  1497.   shr    al,2
  1498.   jnc    @@L1
  1499.   cmp    al,63
  1500.   je    @@L1
  1501.   inc    al
  1502.       @@L1:
  1503.   out    dx,al
  1504.  
  1505.   lodsb            ; green
  1506.   shr    al,2
  1507.   jnc    @@L2
  1508.   cmp    al,63
  1509.   je    @@L2
  1510.   inc    al
  1511.       @@L2:
  1512.   out    dx,al
  1513.  
  1514.   lodsb            ; blue
  1515.   shr    al,2
  1516.   jnc    @@L3
  1517.   cmp    al,63
  1518.   je    @@L3
  1519.   inc    al
  1520.       @@L3:
  1521.   out    dx,al
  1522.  
  1523.   loop    @@LLoop
  1524.  
  1525.     @@LExit:
  1526.   pop    si ds
  1527.   leave
  1528.   retf
  1529. ENDP
  1530.  
  1531.  
  1532. ;*****
  1533. ;***** getBlockPalette
  1534. ;*****
  1535.  
  1536. PROC    C    getBlockPalette
  1537.     ARG    firstReg:WORD,lastReg:WORD,paletteData:DATAPTR
  1538.   push    di
  1539.  
  1540.   les    di,[paletteData]        ; set up
  1541.   mov    dx,3C7h
  1542.   mov    ax,[firstReg]
  1543.   out    dx,al
  1544.   mov    dx,3C9h
  1545.   mov    cx,[lastReg]            ; CX = number of registers
  1546.   sub    cx,ax
  1547.   inc    cx
  1548.   cld
  1549.  
  1550.     @@L1:
  1551.   in    al,dx
  1552.   shl    al,2
  1553.   stosb            ; red
  1554.   in    al,dx
  1555.   shl    al,2
  1556.   stosb            ; green
  1557.   in    al,dx
  1558.   shl    al,2
  1559.   stosb            ; blue
  1560.   loop    @@L1
  1561.  
  1562.     @@LExit:
  1563.   pop    di
  1564.   leave
  1565.   retf
  1566. ENDP
  1567.  
  1568.  
  1569. ;*****
  1570. ;***** clearGraphics
  1571. ;*****
  1572.  
  1573. PROC    C    clearGraphics_scr_copy
  1574.     ARG    colour:BYTE
  1575.   mov   dx,SC_INDEX
  1576.   mov   ax,0F02h
  1577.   out   dx,ax               ; enable writes to all four planes
  1578.  
  1579.   mov    ax,0A000h
  1580.   mov    es,ax
  1581.   xor    di,di
  1582.   cld
  1583.   mov    cx,21600
  1584.   mov    al,[colour]
  1585.   mov    ah,al
  1586.  
  1587.   rep    stosw
  1588.   leave
  1589.   retf
  1590. ENDP
  1591.  
  1592.  
  1593.     ENDS
  1594. END